// -----------------------------------------------------------------------------------------------
// (C) Copyright 2011 by Lake Quincy Media. All rights reserved.
//
// Common code for m.js
// -----------------------------------------------------------------------------------------------

if ( LqmAds === undefined )
{
    var LqmAds =
    {
        //-----------------------------------------------------------------------------------------
        // Search term stuff

        GetQueryTerms: function ()
        {
            // common search engine domains with their search term querystring parameter
            var searchEngines = [
                { d: "www.google.", q: "q=" },
                { d: "www.bing.com", q: "q=" },
                { d: "search.live.com", q: "q=" },
                { d: "search.yahoo.com", q: "p=" },
                { d: "codeproject.com", q: "q=" },
                { d: "msdn.microsoft.com", q: "query=" },
                { d: "localhost", q: "q=" }
            ];

            function GetSearchTermKey( url )
            {
                var searchKey = "";
                for ( var i = 0; i < searchEngines.length; i++ )
                {
                    var se = searchEngines[i];
                    if ( url.indexOf( se.d ) >= 0 )
                    {
                        searchKey = se.q;
                        break;
                    }
                }
                return searchKey;
            };

            function GetQueryStringParameter( searchKeyTerm, referrer )
            {
                var startPos = referrer.toLowerCase().indexOf( searchKeyTerm );
                if ( ( startPos < 0 ) || ( startPos + searchKeyTerm.length >= referrer.length ) )
                {
                    return "";
                }
                var endPos = referrer.indexOf( "&", startPos );
                if ( endPos < 0 )
                {
                    endPos = referrer.length;
                }

                var queryString = referrer.substring( startPos + searchKeyTerm.length, endPos );
                // fix the space characters
                queryString = queryString.replace( /%20/gi, " " );
                queryString = queryString.replace( /\+/gi, " " );
                // remove the quotes (if you're really creative, you could search for the
                // terms within the quotes as phrases, and everything else as single terms)
                queryString = queryString.replace( /%22/gi, "" );
                queryString = queryString.replace( /\"/gi, "" );

                return queryString;
            };

            function FormatSearchTerms( searchQuery )
            {
                if ( searchQuery == undefined )
                    return "";

                // matches anything the is NOT a search term
                var rgxQueryStripper = /\bAND\b|\bNOT\b|^NOT\b|\bOR\b|\B\+|\B\-|[^A-Z0-9\+\-\#\._\s]+|\b[A-Z0-9]+:/gi;

                // strip out all the non-terms such as AND, NOT, OR, &, field:, (, ), +, -
                var formattedSearchTerms = $.trim( searchQuery );
                if ( formattedSearchTerms )
                {
                    formattedSearchTerms = formattedSearchTerms.replace( rgxQueryStripper, " " );

                    // strip out multiple whitespace charaters and and commas.
                    formattedSearchTerms = formattedSearchTerms.replace( /\s+/g, " " );
                    return formattedSearchTerms;
                }
                else
                {
                    return "";
                }
            };

            var url = document.URL;
            var searchTerms = "";
            var searchTermKey = GetSearchTermKey( url );

            if ( searchTermKey != "" )
            {
                searchTerms = FormatSearchTerms( GetQueryStringParameter( searchTermKey, url ) );
            }

            if ( searchTerms == "" )
            {
                url = document.referrer.toLocaleLowerCase();
                if ( !url )
                    return "";

                searchTermKey = GetSearchTermKey( url );

                if ( searchTermKey != "" )
                {
                    searchTerms = FormatSearchTerms( GetQueryStringParameter( searchTermKey, url ) );
                }
            }

            return searchTerms;
        },

        // End of Search Term stuff
        //-----------------------------------------------------------------------------------------

        // generate a random ID for the page
        GetRandom: function ( len, base )
        {
            var result, i, j;
            result = '';
            for ( j = 0; j < len; j++ )
            {
                i = Math.floor( Math.random() * base ).toString( base ).toUpperCase();
                result = result + i;
            }
            return result;
        },

        //-----------------------------------------------------------------------------------------
        // Tag stuff
        PageRandomNumber: null,
        PageSearchTerms: null,
        Tile: 1,

        BuildIFrameTag: function ( requestData )
        {
            var tagHtml =
            "<iframe id=\"lqmad{tile}\"  ";
            if ( requestData && requestData.width && requestData.width > 1 )
                tagHtml = tagHtml + "width=\"{width}\" ";
            else
                tagHtml = tagHtml + "width=\"100%\" ";

            if ( requestData && requestData.width && requestData.height > 0 )
                tagHtml = tagHtml + "height=\"{height}\" ";
            else
                tagHtml = tagHtml + "height=\"0\" ";

            tagHtml = tagHtml + "marginwidth=\"0\" marginheight=\"0\" frameborder=\"0\" scrolling=\"no\">" +
            "</iframe>" +
            "<noscript>" +
            "<a href=\"http://ad.doubleclick.net/jump/{sitename}/{zonename};{searchterm}sz={format};abr=!ie4;abr=!ie5;abr=!ie6;{type}tile={tile};ord={timestamp}?\" target=\"{target}\">" +
            "<img src=\"http://ad.doubleclick.net/ad/{sitename}/{zonename};{searchterm}sz={format};abr=!ie4;abr=!ie5;abr=!ie6;{type}tile={tile};ord={timestamp}?\" width=\"{width}\" height=\"{height}\" border=\"0\" alt=\"\"></a></noscript>";

            return this.ReplacePlaceholders( tagHtml, requestData );
        },

        BuildJavaScriptTag: function ( requestData )
        {
            var tagJS = "<scri" + "pt language=\"JavaScript\" " +
            "src=\"http://ad.doubleclick.net/adj/{sitename}/{zonename};{searchterm}sz={format};{type}tile={tile};ord={timestamp}?\" " +
            "type=\"text/javascript\"></scri" + "pt>";

            return this.ReplacePlaceholders( tagJS, requestData );
        },

        ReplacePlaceholders: function ( tagHtml, requestData )
        {
            tagHtml = tagHtml.replace( /\{sitename\}/g, requestData.sitename );
            tagHtml = tagHtml.replace( /\{zonename\}/g, requestData.zonename );

            if ( requestData.tags )
                tagHtml = tagHtml.replace( /\{searchterm\}/g, "kw=" + encodeURIComponent( requestData.tags ) + ";" );
            else
                tagHtml = tagHtml.replace( /\{searchterm\}/g, "" );

            tagHtml = tagHtml.replace( /\{tile\}/g, requestData.tile.toString() );
            tagHtml = tagHtml.replace( /\{format\}/g, requestData.format );
            tagHtml = tagHtml.replace( /\{width\}/g, requestData.width );
            tagHtml = tagHtml.replace( /\{height\}/g, requestData.height );
            tagHtml = tagHtml.replace( /\{target\}/g, requestData.target );
            tagHtml = tagHtml.replace( /\{timestamp\}/g, this.PageRandomNumber );

            if ( requestData.type )
                tagHtml = tagHtml.replace( /\{type\}/g, "type=" + encodeURIComponent( requestData.type ) + ";" );
            else
                tagHtml = tagHtml.replace( /\{type\}/g, "" );

            return tagHtml;
        },

        // End of Tag Stuff
        //-----------------------------------------------------------------------------------------

        //-----------------------------------------------------------------------------------------
        // Mapping from Lake Quincy to DART information

        tagInfo: [
        //ID	Name	                                Height      Width
            {id: 1, n: 'Standard Banner', h: 60, w: 468 },
            { id: 2, n: 'Product Spotlight', h: 2, w: 1 },
            { id: 3, n: 'Hosting Spotlight', h: 2, w: 1 },
            { id: 4, n: 'Skyscraper', h: 600, w: 120 },
            { id: 5, n: 'Square', h: 125, w: 125 },
            { id: 6, n: 'Medium Rectangle', h: 250, w: 300 },
            { id: 7, n: 'Large Rectangle', h: 280, w: 336 },
            { id: 8, n: 'Leaderboard', h: 90, w: 728 },
            { id: 9, n: 'HTML Ad', h: 0, w: 0 },
            { id: 10, n: 'Fixed Square', h: 125, w: 125 },
            { id: 11, n: 'Fixed Banner', h: 60, w: 468 },
            { id: 12, n: 'Half Skyscraper', h: 300, w: 120 },
            { id: 13, n: 'IAB Button', h: 90, w: 120 },
            { id: 14, n: 'Rectangle', h: 120, w: 150 },
            { id: 15, n: 'Thin Horizontal', h: 27, w: 408 },
            { id: 16, n: 'Button', h: 30, w: 100 },
            { id: 17, n: 'DogEar', h: 0, w: 0 },
            { id: 18, n: 'Wide Skyscraper', h: 600, w: 160 },
            { id: 19, n: 'Tracking Only', h: 1, w: 1 },
            { id: 20, n: 'Mixed 120x90-Text', h: 5, w: 1 },
            { id: 21, n: 'Home page top left (150 X 80)', h: 80, w: 150 },
            { id: 22, n: 'SponsorEmail', h: 0, w: 0 },
            { id: 23, n: 'Email', h: 60, w: 60 },
            { id: 24, n: 'TextLinks', h: 0, w: 0 },
            { id: 25, n: 'Zone', h: 0, w: 0 },
            { id: 26, n: 'Goal group', h: 0, w: 0 },
            { id: 27, n: 'Article', h: 0, w: 0 },
            { id: 28, n: 'Search Sponsor Box', h: 30, w: 120 },
            { id: 29, n: 'Microbar', h: 31, w: 88 },
            { id: 30, n: 'Sponsor Link', h: 1, w: 0 }
        ],

        DetermineTagSize: function ( requestData )
        {
            if ( requestData.format )
            {
                if ( !isNaN( requestData.format ) )
                {
                    var found = false;
                    var i = 0;
                    while ( i < this.tagInfo.length && !found )
                    {
                        var adFormat = this.tagInfo[i];
                        if ( adFormat.id == requestData.format )
                        {
                            if ( adFormat.w != 0 )
                                requestData.width = adFormat.w;
                            if ( adFormat.h != 0 )
                                requestData.height = adFormat.h;
                            requestData.type = adFormat.name;
                            found = true;
                            requestData.format = "" + adFormat.w + "x" + adFormat.h;
                        }
                        i++;
                    }
                }
            }
        },

        lqmIdToDartMap: [
        // Lake Quincy Publisher Site ID	DART Site Name	Site Name
        // latest additions
            {id: 8999, n: "wp7fr" },             //Windows Phone 7Apps France
            {id: 9175, n: "coldfusionex" },      //ColdFusion Example
            {id: 10541, n: "pdaphone" },         //PDA Phone Home
            {id: 10537, n: "swishtalk" },        //Swish Talk

            {id: 403, n: "netans" },             //.NET Answers
            {id: 173, n: "netcurry" },           //.NET curry
            {id: 558, n: "netmixer" },           //.NET Mixer
            {id: 777, n: "netrock" },            //.NET Rocker - Silverlight, SharePoint, and All things .NET
            {id: 483, n: "netstuff" },           //.NET Stuff from My Desktop
            {id: 735, n: "nettechq" },           //.Net Technoloy Quest
            {id: 9063, n: "nettv" },             //.NET TV
            {id: 51, n: "a1vb" },                //A1VBCode
            {id: 278, n: "adamtibisblog" },      //Adam Tibi's Blog
            {id: 462, n: "adilswebblog" },       //Adil's Weblog
            {id: 7896, n: "adonet" },            //ADO.Net and SQL
            {id: 807, n: "alnyveldt" },          //Al Nyveldt's Blog
            {id: 7913, n: "allcomputer" },       //All Computer
            {id: 821, n: "alvinashcraft" },      //Alvin Ashcraft's Blog
            {id: 383, n: "andreavb" },           //AndreaVB Programming
            {id: 599, n: "apulvyas" },           //Apul Vyas' Blog
            {id: 328, n: "ardent" },             //Ardent Dev Blog
            {id: 4287, n: "artem" },             //Artem's Blog
            {id: 207, n: "ashishware" },         //Ashishware
            {id: 49, n: "aspadvice" },           //ASP Advice
            {id: 1, n: "aspa" },                 //ASP Alliance
            {id: 33, n: "aspauthors" },          //ASP Authors
            {id: 642, n: "aspdotnetcodebook" }, //ASP Dot Net Code Book
            {id: 8982, n: "aspdotnetonline" },   //ASP Dot Net Codes Online
            {id: 3485, n: "aspnet101" },         //ASP NET 101
            {id: 369, n: "aspsnippets" },        //ASP Snippets
            {id: 75, n: "aspspider" },           //ASP Spider
            {id: 8675, n: "aspnetbook" },        //ASP.NET Book
            {id: 224, n: "aspnetcodes" },        //ASP.NET Codes
            {id: 557, n: "aspnetdeveloper" },    //ASP.NET Developer
            {id: 759, n: "aspnetdevresource" },  //ASP.Net Development Resource
            {id: 360, n: "aspnetexample" },      //ASP.NET Example
            {id: 433, n: "aspnetfaq" },          //ASP.NET FAQ
            {id: 237, n: "aspnetmvc" },          //ASP.NET MVC
            {id: 88, n: "aspnetpodcast" },       //ASP.NET Podcast
            {id: 8699, n: "aspnetpond" },        //ASP.NET Pond
            {id: 348, n: "aspnetquest" },        //ASP.NET QUEST
            {id: 616, n: "aspdotnet-suresh" },   //aspdotnet-suresh Blog
            {id: 20, n: "aspsmith" },            //ASPSmith
            {id: 322, n: "ayenderahiens" },      //Ayende Rahien's Blog
            {id: 309, n: "azurefeeds" },         //Azure Feeds
            {id: 160, n: "beansoftware" },       //Bean Software
            {id: 302, n: "billbeckelman" },      //Bill Beckelman's Blog
            {id: 78, n: "binaryintellect" },     //Binary Intellect
            {id: 79, n: "bipinjoshi" },          //Bipin Joshi's Code
            {id: 155, n: "bipinjoshinet" },      //Bipin Joshi's Blog
            {id: 8291, n: "blackbeltcoder" },    //Black Belt Coder
            {id: 104, n: "blocks4net" },         //Blocks4.NET
            {id: 569, n: "bloglaurentduveau" },  //Blog of Laurent Duveau
            {id: 763, n: "blueonion" },          //Blue Onion Software
            {id: 1129, n: "bobcraven" },         //Bob Cravens' Blog
            {id: 734, n: "breakpointslive" },    //Breakpoints Live
            {id: 516, n: "brendanenrick" },      //Brendan Enrick's Blog
            {id: 589, n: "brentlamborn" },       //Brent Lamborn's Blog
            {id: 470, n: "briannoyes" },         //Brian Noyes' Blog
            {id: 381, n: "brianpeek" },          //Brian Peek's Blog
            {id: 413, n: "bytemycode" },         //byte My Code
            {id: 610, n: "cfanatic" },           //C Fanatic
            {id: 732, n: "cprogramming" },       //C Programming
            {id: 240, n: "csharpfriends" },      //C Sharpfriends 
            {id: 8782, n: "csharpblog" },        //C# blog
            {id: 172, n: "csharpfeeds" },        //C# Feeds
            {id: 9114, n: "csharpforums" },      //C# Forums
            {id: 994, n: "csharphelp" },         //C# Help
            {id: 365, n: "csharpnetfreak" },     //C#.NET Freak
            {id: 1132, n: "csharperimage" },     //C#er: Image
            {id: 464, n: "csharpnedir" },        //C#nedir?
            {id: 756, n: "cametoofar" },         //CameTooFar
            {id: 2579, n: "chadmoran" },         //Chad Moran's Blog
            {id: 9225, n: "chriskoenig" },       //Chris Koenig's Blog
            {id: 345, n: "codeaspnet" },         //Code ASP.NET
            {id: 797, n: "codebetter" },         //Code Better
            {id: 985, n: "codecapers" },         //Code Capers
            {id: 501, n: "codegain" },           //Code Gain
            {id: 3735, n: "codegeeks" },         //Code Geeks
            {id: 1174, n: "codekeep" },          //Code Keep
            {id: 629, n: "codecallprogram" },    //CodeCall Programming Forum
            {id: 804, n: "codeclimber" },        //Codeclimber.NET
            {id: 260, n: "codedigest" },         //CodeDigest.Com
            {id: 373, n: "codeglobe" },          //CodeGlobe
            {id: 445, n: "codepaste" },          //CodePaste.NET
            {id: 813, n: "codejournal" },        //Coder Journal
            {id: 838, n: "coderslife" },         //Coders Life
            {id: 303, n: "codeverge" },          //CodeVerge
            {id: 261, n: "codinghorror" },       //Coding Horror Blog
            {id: 321, n: "codeinstinct" },       //Coding Instinct
            {id: 898, n: "codingqa" },           //Coding QA
            {id: 699, n: "compgroups" },         //Compgroups.net
            {id: 59, n: "connectionstrings" },   //Connection Strings
            {id: 830, n: "coreyhaines" },        //Corey Haines' Blog
            {id: 6, n: "coveryourasp" },         //CoverYourASP
            {id: 8836, n: "cpfaqtec" },          //CPFAQ TECH BLOG
            {id: 711, n: "csharptalk" },         //csharptalk.com
            {id: 154, n: "cy2" },                //CY2 Online
            {id: 703, n: "d2zone" },             //d2zone
            {id: 4222, n: "dailynettips" },      //Daily .NET Tips
            {id: 8607, n: "dailycoding" },       //Daily Coding
            {id: 1033, n: "diaryofninja" },      //Dairy of a Ninja
            {id: 92, n: "databasedev" },         //DatabaseDev.co.uk
            {id: 827, n: "davebosts" },         //Dave Bost's Blog
            {id: 805, n: "davedonaldson" },      //Dave Donaldson's Blog
            {id: 672, n: "debugging" },          //Debugging.com
            {id: 307, n: "deepfriedbytes" },     //Deep Fried Bytes Podcast
            {id: 8314, n: "deliciousdotnet" },   //Delicious Dot Net
            {id: 4253, n: "delta" },             //Delta's Blog
            {id: 7284, n: "denis" },             //Denis' Blog
            {id: 836, n: "dennyboynton" },       //Denny Boynton's Blog
            {id: 513, n: "devnews" },            //Dev News Groups
            {id: 443, n: "devcurry" },           //DevCurry
            {id: 48, n: "developerfusion" },     //Developer Fusion
            {id: 605, n: "developerIT" },        //Developer IT
            {id: 842, n: "devhawk" },            //DevHawk.net
            {id: 1160, n: "devlico" },           //Devlicio.us
            {id: 849, n: "devv" },               //Devv.com
            {id: 401, n: "diggingtech" },        //Digging Technology
            {id: 810, n: "dimecast" },           //Dimecast.net
            {id: 245, n: "directoryprogram" },   //Directory Programming .NET
            {id: 8276, n: "dofactory" },         //DoFactory -- .NET Design Patterns and Architecture
            {id: 231, n: "donnfelker" },         //Donn Felker's Blog
            {id: 695, n: "door2windows" },       //Door2Windows
            {id: 29, n: "dotnet247" },           //Dot Net 247
            {id: 185, n: "dotnetalbum" },        //Dot Net Album
            {id: 42, n: "dotnetbips" },          //Dot Net Bips
            {id: 613, n: "dotnetcodes" },        //Dot Net Codes
            {id: 4265, n: "dotnetdude" },        //Dot Net Dude
            {id: 7413, n: "dotnetexamples" },    //Dot net Examples
            {id: 210, n: "dotnetfunda" },        //Dot Net Funda
            {id: 764, n: "dotnetguts" },         //Dot Net Guts
            {id: 4230, n: "dotnethelp" },        //Dot Net Help
            {id: 44, n: "dotnetjohn" },          //Dot Net John
            {id: 879, n: "dotnetkicks" },        //Dot Net Kicks
            {id: 741, n: "dotnetobject" },       //Dot Net Object
            {id: 323, n: "dotnetpearls" },       //Dot Net Perls
            {id: 752, n: "dotnetprogram" },      //Dot Net Programming Made Easy
            {id: 545, n: "dotnetref" },          //Dot Net Reference
            {id: 293, n: "dotnetshoutout" },     //Dot Net Shoutout
            {id: 70, n: "dotnetslackers" },      //Dot Net Slackers
            {id: 449, n: "dotnetspark" },        //Dot Net Spark
            {id: 611, n: "dotnetspeaks" },       //Dot Net Speaks
            {id: 68, n: "dotnetspider" },        //Dot Net Spider
            {id: 713, n: "dotnetsquare" },       //Dot Net Square
            {id: 375, n: "dotnetthread" },       //Dot Net Thread
            {id: 285, n: "dotnettipstricks" },   //Dot Net Tips & Tricks
            {id: 4271, n: "dotnettoolkit" },     //Dot Net ToolKit
            {id: 623, n: "dotnetuncle" },        //Dot Net Uncle
            {id: 112, n: "dreamincode" },        //Dream In Code
            {id: 6259, n: "eaglet" },            //eaglet.cnblogs
            {id: 704, n: "ec-tech" },            //EC-Tech Blog
            {id: 621, n: "edutechnow" },         //Education Technology Now
            {id: 658, n: "edutechnicians" },     //EduTechnicians
            {id: 835, n: "elegantcode" },        //Elegant Code
            {id: 895, n: "elijahmanor" },        //Elijah Manor
            {id: 199, n: "encosia" },            //Encosia
            {id: 4233, n: "everythingsilverlight" }, //Everything Silverlight
            {id: 97, n: "exforsys" },            //Exforsys.com
            {id: 617, n: "f1tutorials" },        //F1Tutorials
            {id: 9597, n: "farblondz" },         //Farblondzshet in Code
            {id: 799, n: "frazzleddad" },        //Frazzleddad
            {id: 148, n: "freeyutes" },          //Free Yutes
            {id: 825, n: "galasoftlaurent" },    //Galasoft Laurent Bugnion's Blog
            {id: 4223, n: "geeksoncoding" },     //Geeks On Coding
            {id: 560, n: "geekswithblogs" },     //Geekswithblogs.net
            {id: 1099, n: "gilfink" },           //Gil Fink's Blog
            {id: 577, n: "go4expert" },          //Go 4 Expert.com
            {id: 654, n: "go4answers" },         //Go4Answers
            {id: 9076, n: "goodcoderscode" },    //good coders code, great coders reuse
            {id: 590, n: "gregscoolthing" },     //Greg's Cool Thing of the Day 
            {id: 772, n: "guide4it" },           //Guides4IT
            {id: 1025, n: "gurushop" },          //GuruStop - .NET & Web Dev Posts
            {id: 4288, n: "hackingsilverlight" }, //Hacking Silverlight
            {id: 426, n: "heartysoft" },         //Heartysoft
            {id: 103, n: "highoncoding" },       //High On Coding
            {id: 7835, n: "himabinduvjella" },   //Himabinduvejella
            {id: 7850, n: "howtoarticles" },     //How To Articles
            {id: 4277, n: "huddledmasses" },     //Huddled Masses
            {id: 7941, n: "i2fly" },             //i2fly 
            {id: 208, n: "ineta" },              //INETA North America
            {id: 8460, n: "integratedwebsys" },  //Integrated Web Systems
            {id: 571, n: "iprogrammer" },        //iProgrammer
            {id: 193, n: "Iserializable" },      //ISerializable
            {id: 7851, n: "j2ee" },              //J2EE web development tutorial
            {id: 1090, n: "jamessenior" },       //James Senior's Blog
            {id: 853, n: "jasonfollas" },        //Jason Follas' Blog
            {id: 90, n: "jasongaylord" },        //Jason Gaylord's Blog
            {id: 9185, n: "javaeclipseandroid" }, //Java, Eclipse, Android and Web Programming Tutorials
            {id: 4213, n: "jeffblankenburg" },   //Jeff Blankenburg's Blog
            {id: 1066, n: "jeffhandley" },       //Jeff Handley
            {id: 469, n: "jeffwidmer" },         //Jeff Widmer's Blog
            {id: 230, n: "jeffreypalermo" },     //Jeffrey Palermo
            {id: 1041, n: "jessliberty" },       //Jesse Liberty's Blog
            {id: 803, n: "joelross" },           //Joel Ross' Blog
            {id: 232, n: "johnpapa" },           //JohnPapa.net
            {id: 785, n: "lqn.jongalloway" },        //Jon Galloway
            {id: 808, n: "joshholmes" },         //Josh Holmes' Blog
            {id: 7297, n: "jquerybyex" },        //jQuery By Example
            {id: 4212, n: "karlfleischmann" },   //KarlFleischmann.com
            {id: 62, n: "kbalertz" },            //kbAlertz.com
            {id: 811, n: "keithelder" },         //Keith Elder
            {id: 823, n: "kenegozi" },           //Kenegozi Blog
            {id: 268, n: "keralamicrosoft" },    //Kerala Microsoft Users Group
            {id: 774, n: "kevindockx" },         //Kevin Dockx's Blog
            {id: 822, n: "kevinpang" },          //Kevin Pang's Blog
            {id: 858, n: "kodefuguru" },         //Kode Fu Guru
            {id: 162, n: "kodyaz" },             //Kodyaz
            {id: 1121, n: "krisvandermast" },    //Kris van der Mast's Blog
            {id: 4274, n: "kunal" },             //Kunal's Blog
            {id: 814, n: "lazycoder" },          //Lazy Coder
            {id: 175, n: "learnxpress" },        //Learn xpress
            {id: 656, n: "learnentityframework" }, //LearnEntityFramework
            {id: 701, n: "learningsharepoint" }, //Learning sharePoint
            {id: 841, n: "leedumond" },          //Lee Dumond's Blog
            {id: 7206, n: "lexli" },             //Lex Li's blog
            {id: 83, n: "lhotka" },              //Lhotka.net
            {id: 812, n: "lostechies" },         //Los Techies.
            {id: 911, n: "maartenballiauw" },    //Maarten Balliauw Blog
            {id: 693, n: "markysegger" },        //Markus Egger's Xamalot
            {id: 2198, n: "mattoborn" },         //Matt Oborn's Blog
            {id: 4214, n: "mehmetakif" },        //Mehmet Akif CAKAR's Web Blog
            {id: 8624, n: "methods&tools" },     //Methods & Tools
            {id: 8260, n: "miamicoder" },        //Miami Coder
            {id: 798, n: "michaeleaton" },       //Michael Eaton's Blog
            {id: 7734, n: "msftaccessforum" },   //Microsoft Access Forums
            {id: 781, n: "msftaccesshelpctr" },  //Microsoft Access Help Center
            {id: 288, n: "msftconsultants" },    //Microsoft Consultant's World
            {id: 524, n: "msftnow" },            //microsoft NOW
            {id: 553, n: "msftSharepointManish" }, //Microsoft SharePoint Manish's Blog
            {id: 736, n: "msfttechnologies" },   //Microsoft Technologies
            {id: 153, n: "msftnettech" },        //Microsoft.NET Technology Blog
            {id: 447, n: "msftfeed" },           //MicrosoftFeed
            {id: 279, n: "moses" },              //Moses' Blog
            {id: 541, n: "msdotnetmentor" },     //MS Dot Net Mentor
            {id: 533, n: "msgroups" },           //MSGroups.net
            {id: 402, n: "msigeek" },            //Msigeek
            {id: 956, n: "mvwood" },             //MVWood.com
            {id: 7562, n: "mypublichinterface" }, //My Public Interface
            {id: 618, n: "mywindowsclub" },      //My Windows Club
            {id: 379, n: "mytechmantra" },       //myTechMantra
            {id: 6671, n: "nathantotten" },      //Nathan Totten's Blog
            {id: 831, n: "nayyerikeyvan" },      //Nayyeri Keyvan's Blog
            {id: 751, n: "net-info" },           //net-informations.com
            {id: 578, n: "netprogramminghelp" }, //NetProgrammingHelp
            {id: 776, n: "net-tutorials" },      //net-tutorials.com
            {id: 459, n: "niksgaur" },           //Niksgaur's Blog
            {id: 659, n: "nlogadvanced" },       //NLog - Advanced .NET
            {id: 142, n: "odetocode" },          //Ode To Code
            {id: 843, n: "olegsych" },           //Oleg Sych's Blog
            {id: 768, n: "omnitechnews" },       //OmniTechNews
            {id: 8484, n: "optimisewindows" },   //Optimise Windows
            {id: 512, n: "pakistandevnetwork" }, //Pakistan Developers Network
            {id: 264, n: "paraswadehramsdn" },   //Paras Wadehra MSDN Blog
            {id: 131, n: "peterkellner" },       //Peter Kellner's Blog
            {id: 209, n: "peterritchie" },       //Peter Ritchie's MVP blog
            {id: 87, n: "ppolymorphicpodcast" }, //Polymorphic Podcast
            {id: 269, n: "powershell" },         //Powershell
            {id: 421, n: "praveensworld" },      //Praveen's World Blog
            {id: 683, n: "rbshare" },            //RBShare
            {id: 166, n: "realwrldsoftware" },   //Real World Software Architecture
            {id: 107, n: "regexadvice" },        //Regex Advice
            {id: 50, n: "regexlib" },            //RegExLib
            {id: 8202, n: "richardbanks" },      //Richard Banks - Agile and .NET
            {id: 258, n: "rickstrahl" },         //Rick Strahl's Web Log
            {id: 239, n: "robhoward" },          //Rob Howard's Blog
            {id: 987, n: "robmensching" },       //Rob Mensching's Blog
            {id: 862, n: "robzelt" },            //Rob Zelt's Blog
            {id: 639, n: "rtsevenlite" },        //RT Seven Lite
            {id: 570, n: "rtwincustomize" },     //RT WinCustomize
            {id: 204, n: "ryandunn" },           //Ryan Dunn's Blog
            {id: 818, n: "ryanfarley" },         //Ryan Farley's Blog
            {id: 597, n: "sachabarber" },        //Sacha Barber's Blog
            {id: 76, n: "samplecodepool" },      //Sample Code Pool
            {id: 1094, n: "samueljack" },        //Samuel Jack's Blog
            {id: 1013, n: "samuelmoura" },       //Samuel Moura Development Blog
            {id: 454, n: "satalajmore" },        //satalaj More
            {id: 263, n: "scottallen" },         //Scott Allen's Blog
            {id: 500, n: "scottcate" },          //Scott Cate's Blog
            {id: 251, n: "scotthanselman" },     //Scott Hanselman's ComputerZen
            {id: 52, n: "scottonwriting" },      //ScottOnWriting
            {id: 531, n: "scriptmanual" },       //Script Manual
            {id: 253, n: "sec_perf" },           //Security and Performance From the Field
            {id: 594, n: "senthikumaitpror" },   //Senthil Kumar - ITPRO 
            {id: 517, n: "senthikumar" },        //Senthil Kumar
            {id: 4215, n: "shahed" },            //Shahed.net
            {id: 7845, n: "sharepoint" },        //SharePoint Blogs
            {id: 7895, n: "sharepointcoding" },  //Sharepoint Codings
            {id: 600, n: "sharepointedutech" },  //Sharepoint Edu Tech
            {id: 584, n: "sharepointelse" },     //SharePoint else...
            {id: 446, n: "sharepointkb" },       //Sharepoint KB
            {id: 3484, n: "sharepointmonitor" }, //SharePoint Monitor
            {id: 635, n: "sharepointprogramming" }, //SharePoint Programming
            {id: 678, n: "sharepointsolutions" }, //Sharepoint Solutions
            {id: 829, n: "shinedraw" },          //Shine Draw
            {id: 177, n: "shiningstarserv" },    //Shining Star Services, LLC
            {id: 380, n: "shrinkrays" },         //Shrinkrays
            {id: 398, n: "silverlightcream" },   //Silverlight Cream
            {id: 330, n: "silverlightexchange" }, //Silverlight Exchange
            {id: 314, n: "silverlightfeeds" },   //Silverlight Feeds
            {id: 592, n: "silverlighttips" },    //Silverlight Tips of the Day
            {id: 675, n: "silverlightclub" },    //SilverlightClub
            {id: 4229, n: "silverlightzone" },   //Silverlight-Zone
            {id: 225, n: "simpable" },           //Simpable
            {id: 834, n: "slickticket" },        //Slick Ticket
            {id: 357, n: "smallorkarounds" },    //Small Workarounds
            {id: 1028, n: "smartypantscoding" }, //Smarty Pants Coding
            {id: 8748, n: "snippertbank" },      //Snippet Bank
            {id: 965, n: "snowball" },           //Snowball - The Blog
            {id: 773, n: "softwaredeveloper" },  //Software Developer
            {id: 297, n: "softwaredevinrealwrld" }, //Software Development in the Real World
            {id: 212, n: "somasegrs" },          //Somasegar's WebLog
            {id: 105, n: "sqladvice" },          //SQL Advice
            {id: 315, n: "sqlfeeds" },           //SQL Feeds
            {id: 7889, n: "sqlserver_busint" },  //SQL Server and Business Intelligence by Gaurav Mittal 
            {id: 488, n: "sqlservercitation" },  //SQL Server Citation
            {id: 354, n: "sqlservercurry" },     //SQL Server Curry
            {id: 333, n: "sqlserverdba" },       //SQL Server DBA
            {id: 744, n: "sqlservertraining" },  //SQL Server Training
            {id: 352, n: "sqltips_tricks" },     //SQL Tips & Tricks
            {id: 327, n: "sqlservervideo" },     //SQLServerVideos
            {id: 82, n: "sreesharp" },           //Sree Sharp 
            {id: 471, n: "srtsolutions" },       //SRT Solutions
            {id: 18, n: "stardeveloper" },       //StarDeveloper
            {id: 72, n: "steveorr,site" },            //Steve Orr's Blog
            {id: 219, n: "stevesmith" },         //Steve Smith's Blog
            {id: 608, n: "snilyadav" },          //Sunil Yadav's Blog
            {id: 487, n: "suratusergrp" },       //Surat User Group
            {id: 990, n: "syncmichael" },        //SyncMichael
            {id: 582, n: "talentcert" },         //TalentCertification
            {id: 256, n: "talesfromevilemp" },   //Tales from the Evil Empire
            {id: 215, n: "tamirkhason" },        //Tamir Khason's Blog
            {id: 542, n: "techtalks" },          //Tech Talks
            {id: 800, n: "techtool" },           //Tech Tool Blog
            {id: 8784, n: "techstory" },         //Technology Story
            {id: 4250, n: "technoscatter" },     //Technoscatter - Drive to Technology
            {id: 2266, n: "theaccidentalgeek" }, //The Accidental Geek
            {id: 440, n: "thecodecollege" },     //The Code College .NET
            {id: 284, n: "thecodecube" },        //The Code Cube - IT Community
            {id: 4266, n: "thecodeking" },       //The Code King
            {id: 283, n: "thecodeonline" },      //The Code Online
            {id: 495, n: "codeproject" },        //The Code Project
            {id: 4269, n: "thecustomizewindows" }, //The Customize Windows
            {id: 655, n: "thedatafarm" },        //the Data Farm
            {id: 8084, n: "thedotthenet" },      //The Dot The Net
            {id: 8552, n: "thegeeksclub" },      //The Geeks Club
            {id: 304, n: "theruntime" },         //The Runtime
            {id: 624, n: "thewindowsclub" },     //The Windows Club
            {id: 7436, n: "thewindowsphonedevcomm" }, //The Windows Phone Developer Community
            {id: 223, n: "thereforsys" },        //Therefore Systems
            {id: 1942, n: "thgwebsite" },        //THG Web Site
            {id: 5838, n: "thoughonnet" },       //Thoughts on .NET
            {id: 115, n: "timheuer" },           //Tim Heuer's Blog
            {id: 312, n: "tipsntricks" },        //Tips n Tracks
            {id: 837, n: "tobinharris" },        //Tobin Harris' Blog
            {id: 202, n: "top54u" },             //top54u
            {id: 8512, n: "totaldotnet" },       //Total Dot Net
            {id: 481, n: "trirandjqgrid" },      //Trirand jqGrid
            {id: 775, n: "twitterlive" },        //Twitterlive.net
            {id: 783, n: "unnaturalactsonsrccode" }, //Unnatural Acts on Source Code
            {id: 1120, n: "vascooliveria" },     //Vasco Oliveira's Blog
            {id: 510, n: "vbnet" },              //VB.NET Forums
            {id: 292, n: "vbatips_tricks" },     //VBA Tips & Tricks
            {id: 606, n: "vishalswami" },        //Vishalswami's Blogspot
            {id: 179, n: "visualanand" },        //Visual Anand
            {id: 463, n: "visualbasicknowbase" }, //Visual Basic Knowledge Base
            {id: 607, n: "visualbasictut" },     //Visual basic.Net tutorial
            {id: 132, n: "visualbuilder" },      //Visual Builder
            {id: 408, n: "visualckicks" },       //Visual C# Kicks
            {id: 548, n: "w3bookmarks" },        //w3bookmarks
            {id: 43, n: "w3schools" },           //W3Schools
            {id: 620, n: "w3vbnet" },            //W3vb.net
            {id: 630, n: "way2tutorial" },       //Way2Tutorial  Free Web Development Tutorial
            {id: 591, n: "webnet" },             //Web.NET
            {id: 625, n: "wedostforum" },        //Wedost Forum
            {id: 110, n: "west-windtech" },      //West-Wind Technologies
            {id: 817, n: "wildermuth" },         //Wildermuth
            {id: 532, n: "williablog" },         //Williablog
            {id: 4218, n: "windows8beta" },      //Windows 8 Beta
            {id: 7325, n: "windows8search" },    //Windows 8 Search
            {id: 108, n: "windowsadvice" },      //Windows Advice
            {id: 1168, n: "windowsdevpwrtools" }, //Windows Developer Power Tools
            {id: 6559, n: "windowsphone7app" },  //Windows Phone 7 Apps
            {id: 794, n: "windowsspace" },       //Windows Space
            {id: 649, n: "windowsvalley" },      //Windows Valley
            {id: 147, n: "wrox" },               //WROX
            {id: 56, n: "wwwcoder" },            //WWW Coder
            {id: 391, n: "wynapse" },            //WynApse
            {id: 106, n: "xmladvice" },          //XML Advice
            {id: 23, n: "xmlforasp" },           //XMLforASP.NET
            {id: 694, n: "yaronnaveh" },         //Yaron Naveh's Web Services 2.0 Blog
            {id: 514, n: "yazilimmutfagi" },     //Yazilim Mutfagi
            {id: 782, n: "youvebeenhacked"}      //You've Been Haacked
        ],

        MapLqmIdsToDart: function ( requestData )
        {
            if ( requestData.publisher )
            {
                if ( isNaN( requestData.publisher ) )
                {
                    requestData.sitename = requestData.publisher;
                }
                else
                {
                    var found = false;
                    var i = 0;
                    while ( i < this.lqmIdToDartMap.length && !found )
                    {
                        if ( this.lqmIdToDartMap[i].id == requestData.publisher )
                        {
                            requestData.sitename = "lqm." + this.lqmIdToDartMap[i].n + ".site";
                            found = true;
                        }
                        i++;
                    }
                    if ( !found )
                    {
                        requestData.sitename = "lqm.pub" + requestData.publisher + ".site";
                    }
                }

                this.MapLqmZoneToDartZone( requestData );

            }
            else if ( requestData.site )
            {
                requestData.sitename = "lqm.codeplex.site";
                requestData.zonename = requestData.site;
            }
        },

        zoneInfo: [
        // general
            {id: 1, n: "ron" },
            { id: 51, n: "it" },
            { id: 52, n: "designer" },
            { id: 2, n: "above_the_fold" },
            { id: 9, n: "wpf" },
            { id: 14, n: "silverlight" },

        // Asp Alliance
            {id: 3, n: "reportingservices" },
            { id: 4, n: "sql" },
            { id: 5, n: "whitepaper" },
            { id: 6, n: "featuredwhitepaper" },
            { id: 7, n: "crystalreports" },
            { id: 10, n: "vs2005video" },
            { id: 11, n: "ros_dogear" },
            { id: 12, n: "homepage_dogear" },
            { id: 13, n: "excludehomepage_dogear" },
            { id: 15, n: "lqm_dogear" },
            { id: 17, n: "mvc" },
            { id: 18, n: "ajax" },
            { id: 38, n: "devexpress_video" },
            { id: 39, n: "devmavens_sidebar" },
            { id: 40, n: "devmavens_offer" },
            { id: 44, n: "silverlight" },
            { id: 45, n: "wpf" },
            { id: 54, n: "csharp_articles" },

        // Code Project
            {id: 71, n: "commerce" },
            { id: 72, n: "sql" },
            { id: 73, n: "mobile" },
            { id: 74, n: "cloud" },
            { id: 75, n: "whitepapers" },
            { id: 76, n: "parallelism" },
            { id: 77, n: "ros" },
            { id: 78, n: "house" },
            { id: 85, n: "wpf_silverlight" },
            { id: 86, n: "dotnet" }
        ],

        MapLqmZoneToDartZone: function ( requestData )
        {
            if ( requestData.zone )
            {
                var found = false;
                var i = 0;
                while ( i < this.zoneInfo.length && !found )
                {
                    if ( this.zoneInfo[i].id == requestData.zone )
                    {
                        requestData.zonename = this.zoneInfo[i].n;
                        found = true;
                    }
                    i++;
                }
                if ( !found )
                {
                    if ( isNaN( requestData.zone ) )
                        requestData.zonename = requestData.zone;
                    else
                        requestData.zonename = "ron";
                }
            }
            else
                requestData.zonename = "ron";
        },

        // End of Mapping from Lake Quincy to DART information 
        //-----------------------------------------------------------------------------------------

        GetDocHeight: function ( doc )
        {
            return doc.height || doc.body && doc.body.scrollHeight;
        },

        HideRefs: function ( doc, theAdDiv, requestData )
        {
            var self = this;
            var context;
            if ( requestData.format.indexOf( "1x" ) === 0 )
            {
                theAdDiv.html( doc.body.innerHTML );
                context = theAdDiv;
            }
            else
                context = doc;

            $( 'a', context ).each( function ()
            {
                var link = $( this );
                var href = link.attr( 'href' );

                link.attr( 'href', 'http://a.lakequincy.com/' + self.GetRandom( 4, 16 ) + "-" + self.GetRandom( 7, 16 ) );

                link.click( function ()
                {
                    link.attr( 'href', href );
                } );
            } );
        }
    };
}

// -----------------------------------------------------------------------------------------------
// (C) Copyright 2011 by Lake Quincy Media. All rights reserved.
//
// Substitute for the Lake Quincy s.js which serves Ads from DART.
//   
// use:
//     <script type="text/javascript"> 
//     <!-- 
//     lqm_channel=1;
//     lqm_publisher=68;
//     lqm_zone=1;
//     lqm_format=7;
//     //-->
//     </script>
//     <script type="text/javascript" src="http://a.lakequincy.com/s.js"></script>
// -----------------------------------------------------------------------------------------------

if (typeof LqmAds.CreateAd !== 'function') 
{
    LqmAds.CreateAd = function ()
        {
            if ( lqm_format && lqm_publisher )
            {
                if ( this.PageRandomNumber == null )
                    this.PageRandomNumber = this.GetRandom( 32, 16 );

                if ( this.PageSearchTerms == null )
                    this.PageSearchTerms = this.GetQueryTerms();

                var requestData = { height: 0, width: 0, format: lqm_format, publisher: lqm_publisher };
                requestData.zone = lqm_zone || 1;

                // and the Ad count
                requestData.tile = this.Tile++;

                // and open new window when clicked
                requestData.target = "_blank";

                // add and search engine query terms to the tags parameter
                if ( this.PageSearchTerms && this.PageSearchTerms != "" )
                {
                    requestData.tags = this.PageSearchTerms;
                }

                this.DetermineTagSize( requestData );
                this.MapLqmIdsToDart( requestData );

                document.write( this.BuildJavaScriptTag( requestData ) );
            }

            // reset the parameters
            var n = null;
            lqm_format = n;
            lqm_publisher = n;
            lqm_zone = n;
        };
}

//---------------------------------------------------------------------------------------------
// do the work
LqmAds.CreateAd();
// end of work
//---------------------------------------------------------------------------------------------

